#include <common.h>

void init_mm(void);
void init_device(void);
void init_ramdisk(void);
void init_irq(void);
void init_fs(void);
void init_proc(void);
#ifdef TIMER_IRQ
void init_timer_irq(void);
void init_timer_irq(){
	printf("initializing timer_irq\n");
	volatile uint64_t* mtimecmp = ( uint64_t*)0x2004000;	
	volatile uint64_t* mtime = (uint64_t*) 0x200BFF8;
  *mtime =(uint64_t)0;
	*mtimecmp = (uint64_t)30000;
	unsigned long mstatus_init =0xa00001808 ;
	unsigned long mie_init = 0x80;
	asm volatile ("csrw mstatus, %0": :"r"(mstatus_init));
	asm volatile ("csrw mie, %0": :"r"(mie_init));

}
#endif

int main() {
  extern const char logo[];
  printf("%s", logo);
  Log("'Hello World!' from Nanos-lite");
  Log("Build time: %s, %s", __TIME__, __DATE__);

#ifdef HAS_CTE
  init_irq();
#endif

#ifdef SOFT_IRQ
	unsigned long mstatus_init =0xa00001808 ;
	unsigned long mie_init = 0x08;
	asm volatile ("csrw mstatus, %0": :"r"(mstatus_init));
	asm volatile ("csrw mie, %0": :"r"(mie_init));
	*(uint64_t*)(0x2000000) = 1;
#endif	
#ifdef TIMER_IRQ
	init_timer_irq();
#endif
  init_mm();

  init_device();

  init_ramdisk();

  init_fs();

  init_proc();
  Log("Finish initialization");

#ifdef HAS_CTE
  yield();
#endif

  panic("Should not reach here");
}
